import { Modal, Form, Input, message } from 'antd'
import React, { useEffect } from 'react'
import { awaitWrap } from '@src/assets/js/tool'
import { updateRequest } from './ajax'

async function updateHandle (id, data, callback) {
  const h = message.loading('提交中', 0)
  const [e] = await awaitWrap(updateRequest(id, data))
  h()
  if (e === null) {
    callback()
  }
}

const { Item, useForm } = Form
const { TextArea } = Input

function Main ({ hide, visible, data, refreshFn }) {
  const [formRef] = useForm()
  useEffect(() => {
    if (!visible && formRef) {
      formRef.resetFields()
    }
  }, [formRef, visible])
  return (
    <Modal title='注销仲裁员' open={visible} onCancel={hide} onOk={() => formRef.submit()}>
      <Form form={formRef} onFinish={d => updateHandle(data.id, { status2: '已注销', ...d }, refreshFn)}>
        <Item name='status_remark2' label='审批意见'>
          <TextArea placeholder='请输入' allowClear />
        </Item>
      </Form>
    </Modal>
  )
}

export default Main
